package project.euler.honk.problem.to150;

public final class Problem145 {

	private static final int SIZE = 1000000;// 000;
	private static final boolean[] done = new boolean[SIZE];

	private static int reverse(int number) {
		int result = 0;
		while (number > 0) {
			result = (10 * result) + (number % 10);
			number /= 10;
		}
		return result;
	}

	private static boolean check(int number) {
		while (number > 0) {
			int tmp = number % 10;
			switch (tmp) {
			case 0:
			case 2:
			case 4:
			case 6:
			case 8:
				return false;
			}
			number = number / 10;
		}
		return true;
	}

	private static int solve() {
		int result = 0;
		for (int i = 1, x = 1; i < SIZE; i++, x++) {
			if (x == 10) {
				x = 0;
				continue;
			}
			if (done[i])
				continue;
			int tmp = reverse(i);
			if (check(i + tmp)) {
				result += 2;
				done[tmp] = true;
			}
		}
		return result;
	}

	public static void main(String[] args) {
		long start = System.currentTimeMillis();
		int result = solve();
		long end = System.currentTimeMillis();
		System.out.println("Result: " + result + " Time: " + (end - start));
	}
}
